/*
 * Network.h
 *
 *  Created on: May 28, 2011
 *      Author: Mario Hock
 */

#ifndef NETWORK_H_
#define NETWORK_H_

#include <ariba/ariba.h>
#include "messages/ChatMessage.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

//#include "simple_socket.h" //XXX
#include <string>
#include "interfaces/Useroutputinterface.h"
#include "Transport.h"
#include "Userdatabase.h"
#include "Phrase_connector.h"
#include "Filetransfer.h"
#include "sync/Dir_syncer.h"
#include "Chat.h"
#include "ariba/utility/system/SystemQueue.h"
#include "UI_multiplexer.h"

#include <boost/filesystem.hpp>
#include <boost/utility.hpp>

using namespace std;

using boost::property_tree::ptree;

using ariba::utility::SystemQueue;
using ariba::utility::SystemEvent;
using ariba::utility::SystemEventType;
using ariba::utility::SystemEventListener;

class Network : public SystemEventListener, boost::noncopyable
{
    typedef Network self;
public:
    static self& instance() {
        static self instance;
        return instance;
    }

	void load();

    void connect();

    void disconnect();

    void meet(string connection_phrase);

    int main_loop();


protected:
    virtual void handleSystemEvent( const SystemEvent& event );


private:
    Network();
    virtual ~Network();
    
    void load_data();
    void save_data();
    void execute_ui_commmands(ptree& command_pt);
    void parseCommands(string& message);

private:
    ariba::Node node;

    Userdatabase users;

    Transport* trans;
    Phrase_connector* phrase_connector;
    Filetransfer* filetransfer;
    Dir_syncer* dir_syncer;
    Chat* chat_service;
    bool finished;
};


#endif /* NETWORK_H_ */
